/**
 * @description: 两个栈实现一个队列
 * @author: huen2015
 */

export class Queue {
	private stackOne: any[]
	private stackTwo: any[]
	constructor() {
		this.stackOne = []
		this.stackTwo = []
	}

	add(item: any) {
		this.stackOne.push(item)
	}

	delete() {
		while (this.stackOne.length) {
			this.stackTwo.push(this.stackOne.pop())
		}

		const deleteItem = this.stackTwo.pop()

		while (this.stackTwo.length) {
			this.stackOne.push(this.stackTwo.pop())
		}

		return deleteItem
	}

	length() {
		return this.stackOne.length
	}
}

// 功能测试
const queue = new Queue()

queue.add(1)
queue.add(2)
queue.add(3)
console.log('length', queue.length())
console.log('delete', queue.delete())
console.log('delete', queue.delete())
console.log('length', queue.length())
